<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>猜数字练习</title>
</head>
<body>
<h3>已生成一个1-100之间的随机数:</h3>
<input type="text" placeholder="请输入你猜是数字！">
<button onclick="guess()">点我验证</button>
<h3>小提示：<span></span></h3>



<script>
    let n = parseInt(Math.random()*100)+1;
    console.log('打嗝小抄'+n);
    var count = 0;
    const guess = function () {
        let num = document.querySelector('input').value;
        let spanE = document.querySelector('span');
        if (!/^\d+$/.test(num)){
            alert('请输入数字');
            return;
        }
        count++;
        if(num>n){
            spanE.innerHTML = '太大了';
        }else if(num<n){
            spanE.innerHTML = '太小了';
        }else{
            spanE.innerHTML = '恭喜你'+count+'猜对了';
        }
    }
</script>
</body>
</html>